home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-25 | 5.9 KB | 191 lines | [UVtx/UVtl] |
- // general functions for the educational math games
- // note: each function saves the drawing environment and restores
- // it before returning
-
-
- //////////////////////////////////////////////////////////////////
- // function askAt:
- // clears a rectangular area, type a prompt and returns the string
- //////////////////////////////////////////////////////////////////
- Function askAt(x, y, width, prompt)
- Local lastPen, res
- lastPen = penName() // save the current pen environment
- Pen name="askAtPen" // use a special pen for this function
- Up
- Goto x, y, 0
- Down
- Fill 1, 65535,65535,65535 // erase width x 20 rectangle
- Repeat 2
- Forward width
- Left 90
- Forward 20
- Left 90
- Up
- Goto x+10, y+5, 0
- Print prompt,move // print the prompt
- res = ask(width - (x()-x+10)) // read the string from the user
- Pen name=lastPen // restore the original environment
- Return res // return the string
-
-
- //////////////////////////////////////////////////////////////////////////////
- // function printOver -- like print, but erases its print area before printing
- //////////////////////////////////////////////////////////////////////////////
- Function printOver(str)
- Local lastRGB, lastY, lastDir, width, height
- lastDir = dir()
- width = sWidth(str)
- lastY = y()
- lastRGB = rgb()
- Goto x(),y()-sDescent(),0
- Color random(65000),
- Fill 1, bg_rgb()
- Repeat 2
- Forward width
- Left 90
- Forward sAscent()+sDescent()
- Left 90
- Goto x(), lastY, lastDir
- Print str
- Color lastRGB
-
-
- ///////////////////////////////////////////////////////////
- // circle -- draw a circle around the current point
- // circleS -- like circle, but save/restore the drawing env
- ///////////////////////////////////////////////////////////
- Function circle(radius, fillRGB, penRGB, penWidth)
- Up
- Goto 0,-radius,0
- Down
- Width penWidth
- Color penRGB
- Fill 1,fillRGB
- Circle radius
- Forward 2*π*radius
- Function circleS(radius, fillRGB, penRGB, penWidth, lastPen)
- lastPen = penName() // save the current pen environment
- Pen name="circlePen", copy=lastPen // use a special pen for this function
- circle(radius, fillRGB, penRGB, penWidth)
- Pen name=lastPen // restore the original environment
-
-
- ////////////////////////////////////////////////////////////////////////////////
- // prFraction - print a fraction at an X,Y location, return the printed width //
- ////////////////////////////////////////////////////////////////////////////////
- Function prFraction(x, y, nom, denom)
- Local lastPen, bar, s1, s2
- lastPen = penName() // save the current pen environment
- Pen name="prFractionPen", copy=lastPen // use a special pen for this function
- s1 = " " . nom . " "
- s2 = " " . denom . " "
- bar = sWidth(s1)
- If sWidth(s2) > bar
- bar = sWidth(s2)
- Up // draw the bar
- Goto x, y, 0
- Down
- Forward bar
- Up // the nom
- Goto x+(bar-sWidth(s1))/2, y+3, dir()
- Print s1
- Goto x+(bar-sWidth(s2))/2, y-(sAscent()+sDescent()), 0
- Print s2
- Pen name=lastPen // restore the original environment
- Return bar
-
-
- ///////////////////////
- // pie -- draw a pie //
- ///////////////////////
- Function pie(x, y, start, delta, radius, patt, color)
- Local lastPen
- lastPen = penName()
- Pen name="animateFractionPen", copy=lastPen
- Goto x, y,start
- Fill patt, color
- Down
- Straight
- Forward radius
- Right 90
- Circle -radius
- Forward radius*2*π*delta/360
- Goto x,y,0
- Pen name=lastPen
-
-
-
- ///////////////////////////////////////////
- // Intro -- print an introductory screen //
- ///////////////////////////////////////////
- Function Intro(line, snd1, snd2)
- Local c,p,x,x1,y,a,i,r,lastPen
- lastPen = penName()
-
- // define 10 erasers -- will be cached for the next run
- randomize()
- Repeat i,1,10
- Picture "Intro P" . i
- Fill 1, 65000-random(32000),32000+random(32000),random(65000)
- Left 5-random(10)
- Repeat 4
- Forward 15
- Left 90
-
- // clear the screen, set a light random background
- Clear 40000+random(25000), 40000+random(25000), 40000+random(25000)
-
- // select the location for the text, init the eraser pens
- Pen name="Intro TE", fontname="Times",fontstyle="Bold",fontsize=20
- x = -width()/2 + (width()-sWidth(line))/2 // center the line
- y = height()/4 // 3/4 of the way
- p = "Intro P" . int(1.5+random(9)) // selected eraser's picture
- Pen name="Intro PE", picture=p, speed=300 // the animated eraser pen
- Up
- Goto x-50, y-8,45
- Down
- Pen name="Intro PW" // the actual white pen
- Up
- Goto x-50, y-8,45
- Down
- Color 65500,65500,65500 // white eraser trail
- Width 10
-
- // the eraser op
- Repeat
- x1 = x()
- r = random(3)
- Sound snd1,nowait
- Repeat 5
- Pen name="Intro PE"
- Forward 9+r
- Pen name="Intro PW"
- Forward 9+r
- Pen name="Intro PE"
- r = random(10)
- Goto x1+15, y-r,45
- Pen name="Intro PW"
- Goto x1+15, y-r,45
- If x() > (x + sWidth(line) + 80)
- Pen name="Intro PE", end="no"
- Forward 1
- Break
- Sound "",wait
-
-
- // print the text, one char at a time
- Pen name="Intro TE"
- Color 5005,16937,52735
- Up
- Goto x,y,0
- Repeat i,1,length(line)
- c = substr(line,i-1,1)
- Print c, move
- If c ≠ " "
- Sound snd2,wait
- Else
- Pause random(0.4)+0.2
-
- // restore env, return
- Pen name=lastPen
-